package com.design.movieticket.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.design.movieticket.entity.Comment;
import com.design.movieticket.mapper.CommentMapper;
import com.design.movieticket.service.CollectService;
import com.design.movieticket.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
    @Resource
    private CommentMapper commentMapper;

    @Override
    public void submitContent(Comment comment) {
        super.save(comment);
    }

    @Override
    public List<Comment> getComment(Long movieId) {
        return commentMapper.selectList(new LambdaQueryWrapper<Comment>().eq(Comment::getMovieId,movieId));
    }

    @Override
    public String getStartScore(Long movieId) {
        String result;
        if (commentMapper.getStartScore(movieId) != null){
            result = commentMapper.getStartScore(movieId).substring(0,3);
        }else{
            result = "0";
        }
        return result;
    }

    @Override
    public void delComment(Long commentId) {
        super.removeById(commentId);
    }
}
